/**
 * Predefined variables
 * Name = UserLayer
 * DateTime = Mon Jan 17 2022 19:40:38 GMT+0800 (中国标准时间)
 * Author = Created by zhj9922
 * FileBasename = UserLayer.ts
 * gitee： https://gitee.com/coyeking
 */
import { UiBase } from '../../uiBase';
 
import { _decorator, sys,Label,Sprite, director } from 'cc';
const { ccclass, property } = _decorator;
import { audioManager } from '../../../framework/audioManager';
import { userGlobal } from '../../../global/userGlobal';
import { helper } from '../../../utils/helper';
import { resourceUtil } from '../../../framework/resourceUtil';
import { constant } from '../../../define/constant';
import { platformHelper } from '../../../utils/platformHelper';
 
@ccclass('UserLayer')
export class UserLayer extends UiBase {
    @property(Label)
    public ui_username: Label = null;

    @property(Sprite)
    public ui_userhead: Sprite = null;
    
    @property(Label)
    public ui_userid: Label = null;
    
    @property(Label)
    public ui_usergold: Label = null;
	
	
    onEnable () {
        super.onEnable();
        
        const info = userGlobal.instance.getUserInfo();
        this.ui_username.string = helper.convertNickname(info.nickname);
        this.ui_userid.string = 'ID: ' + info.id;
        this.ui_usergold.string = info.money;
        resourceUtil.loadRemoteImg(info.avatar,this.ui_userhead);

    };
    
    onDestroy () {};
	
    /**
     * 按钮点击事件
     * @param event 
     * @param customEventData 
     */
	private onClick (event: Event, customEventData: string) {
        audioManager.instance.playSound();

        if (customEventData == 'close'){
            return this.closeAction();
        }else if(customEventData == 'cheang'){
            sys.localStorage.removeItem(constant.LOCAL_STORAGE.USER_TOKEN);
            director.loadScene('loginscence');
        }else if(customEventData == 'copy'){
            let str = `《${userGlobal.instance.getSystemInfo().name}》\n我的ID：${userGlobal.instance.getUserInfo().id}\n我的昵称：${userGlobal.instance.getUserInfo().nickname}`
            platformHelper.copyStr(str);
        }
    }
}

